package com.bdv.md.en;

import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.Semaphore;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bdv.md.model.ListOfVal;
import com.bdv.md.service.URLListService;

//@Component
public enum UrlList {
	USSD("http://192.169.0.10:8080/Portal/ussd_dummy"), 
	//DUMMY USSD RESPONSE
	USSD_RESPONSE("http://192.169.0.10:8080/Portal/"),
	
//	USSD_TOKEN_REQUEST("http://192.169.0.10:8080/Portal/ussd_dummy/token"), 
//	USSD_AMR_REQUEST("http://192.169.0.10:8080/Portal/ussd_dummy/amr"),
//	USSD_LIMKREDIT_REQUEST("http://192.169.0.10:8080/Portal/ussd_dummy/limkredit"),
//	USSD_HISTOKEN_REQUEST("http://192.169.0.10:8080/Portal/ussd_dummy/histoken"),
//	USSD_BILHISTORY_REQUEST("http://192.169.0.10:8080/Portal/ussd_dummy/bilhistory"),
	

	MGT("http://192.169.0.10:8080/Portal/mgt_dummy"), 
	
//	MGT_TOKEN_REQUEST("http://192.169.0.10:8080/Portal/mgt_dummy/token"),
//	MGT_AMR_REQUEST("http://192.169.0.10:8080/Portal/mgt_dummy/amr"),
//	MGT_ALARM_REQUEST("http://192.169.0.10:8080/Portal/mgt_dummy/alarm"),
//	MGT_LIM_KREDIT_REQUEST("http://192.169.0.10:8080/Portal/mgt_dummy/limkredit"),
//	MGT_HISTOKEN_REQUEST("http://192.169.0.10:8080/Portal/mgt_dummy/histoken"),
//	MGT_BILHISTORY_REQUEST("http://192.169.0.10:8080/Portal/mgt_dummy/bilhistory");
	
//	MGT_TOKEN_REQUEST("http://192.168.0.10:8080/Integration/mgt_dummy/token"),
//	MGT_AMR_REQUEST("http://192.168.0.10:8080/Integration/mgt_dummy/amr"),
//	MGT_ALARM_REQUEST("http://192.168.0.10:8080/Integration/mgt_dummy/alarm"),
//	MGT_LIM_KREDIT_REQUEST("http://192.168.0.10:8080/Integration/mgt_dummy/limkredit"),
//	MGT_HISTOKEN_REQUEST("http://192.168.0.10:8080/Integration/mgt_dummy/histoken"),
//	MGT_BILHISTORY_REQUEST("http://192.168.0.10:8080/Integration/mgt_dummy/bilhistory")
	
	
	
//	USSD_TOKEN_REQUEST("http://202.3.208.77:9000/cp/eci"), 
//	USSD_AMR_REQUEST("http://202.3.208.77:9000/cp/eci"),
//	USSD_LIMKREDIT_REQUEST("http://202.3.208.77:9000/cp/eci"),
//	USSD_HISTOKEN_REQUEST("http://202.3.208.77:9000/cp/eci"),
//	USSD_BILHISTORY_REQUEST("http://202.3.208.77:9000/cp/eci"),
//	USSD_SEND_SMS("http://202.3.208.77:9000/cp/eci"),
	
//	MGT_TOKEN_REQUEST("http://180.250.80.173/ism_web/api/respond_topup"),
//	MGT_AMR_REQUEST("http://180.250.80.173/ism_web/api/respond_meterreading"),
//	MGT_ALARM_REQUEST("http://180.250.80.173/ism_web/api/respond_alarm"),
//	MGT_LIM_KREDIT_REQUEST("http://180.250.80.173/ism_web/api/respond_limitkredit"),
//	MGT_HISTOKEN_REQUEST("http://180.250.80.173/ism_web/api/respond_tokenhistory"),
//	MGT_BILHISTORY_REQUEST("http://180.250.80.173/ism_web/api/respond_billinghistory"),
	
	
	USSD_TOKEN_REQUEST, 
	USSD_AMR_REQUEST,
	USSD_LIMKREDIT_REQUEST,
	USSD_HISTOKEN_REQUEST,
	USSD_BILHISTORY_REQUEST,
	USSD_SEND_SMS,
	USSD_AMR_PP_REQUEST,
	USSD_LOAD_PROFILE_PP_REQUEST,
	USSD_EVENT_LOG_PP_REQUEST,
	USSD_BILLING_PP_REQUEST,
	USSD_RECALL_LOAD_PROFILE_PP_REQUEST,
	USSD_TIME_SYNC_PP_REQUEST,
	USSD_REMOTE_PP_REQUEST,
	USSD_SCADA_SYSTEM_PP_REQUEST,
	MGT_TOKEN_REQUEST,
	MGT_AMR_REQUEST,
	MGT_ALARM_REQUEST,
	MGT_LIM_KREDIT_REQUEST,
	MGT_HISTOKEN_REQUEST,
	MGT_BILHISTORY_REQUEST,
	MGT_AMR_PP_REQUEST,
	MGT_LOAD_PROFILE_PP_REQUEST,
	MGT_EVENT_LOG_PP_REQUEST,
	MGT_BILLING_PP_REQUEST,
	MGT_ALARM_PP_REQUEST,
	MGT_RECALL_LOAD_PROFILE_PP_REQUEST,
	MGT_TIME_SYNC_PP_REQUEST,
	MGT_REMOTE_PP_REQUEST,
	MGT_SCADA_SYSTEM_PP_REQUEST,
	MGT_NETWORK_STATUS
	;
	
	private static final Logger logger = Logger.getLogger(UrlList.class);
	private String url;

	private Properties properties;
	
	private void init() {
		System.out.println("init url "+this.toString());
		if (properties == null) {
			properties = new Properties();
			try {
				System.out.println("Loading properties URL List");
				properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("urllist.properties"));
				System.out.println("Properties Loaded "+properties);
				
			} catch (Exception e) {
				System.out.println("Error loading properties : "+e.getMessage());
//				e.printStackTrace();
			}
		}
        url = (String) properties.get(this.toString());
		System.out.println("init success, url: "+url);
//        if (properties == null) {
//            properties = new Properties();
//            try {
//                properties.load(UrlList.class.getResourceAsStream(PATH));
//            }
//            catch (Exception e) {
//                logger.error("Unable to load " + PATH + " file from classpath.", e);
//            }
//        }
//        url = (String) properties.get(this.toString());
    }


	private UrlList(String n) {
		url = n;
	}
	
	private UrlList(){}

	
	private static final Semaphore available = new Semaphore(1);
	public String getUrl() {
		try {
			available.acquire();
			if(url==null){
				init();
			}
			available.release();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return url;
	}

}
